package com.zhilianbao.leyaogo.view.widgets;

import android.content.Context;
import android.text.InputFilter;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zhilianbao.leyaogo.R;

/**
 * Author: hcy
 * Description:修改地址item
 * Created: 2016/10/25 9:42
 */
public class ModifyView extends FrameLayout implements View.OnClickListener{

    public ImageView mIv;

    public TextView mItemNameTv;

    public EditText mModifyEt;

    public LinearLayout mRootView;

    public View mBottomLine;//mBottomLine默认gone

    private int tag;

    public ModifyView(Context context) {
        this(context,null);
    }

    public ModifyView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    private void init(Context context) {
        View view = LayoutInflater.from(context).inflate(R.layout.layout_modify_address_item,null);
        mIv = (ImageView) view.findViewById(R.id.iv);
        mItemNameTv = (TextView) view.findViewById(R.id.tv_item_name);
        mModifyEt = (EditText) view.findViewById(R.id.et_item_modify);
        mRootView = (LinearLayout) view.findViewById(R.id.root_view);
        mModifyEt.setOnClickListener(this);
        mIv.setOnClickListener(this);
        mBottomLine= view.findViewById(R.id.bottom_line);
        addView(view);
    }

    public ModifyView setItemName(String name){
        mItemNameTv.setText(name);
        return this;
    }
    public ModifyView setItemNameColor(int colorResId){
        mItemNameTv.setTextColor(colorResId);
        return this;
    }
    public ModifyView setModifyItemColor(int colorResId){
        mModifyEt.setTextColor(colorResId);
        return this;
    }
    public ModifyView setModifyItemText(String text){
        mModifyEt.setText(text);
        return this;
    }
    public ModifyView setModifyItemHintText(String text){
        mModifyEt.setHint(text);
        return this;
    }
    public ModifyView setModifyItemCanEdit(boolean edit){
        mModifyEt.setFocusable(edit);
        return this;
    }
    public ModifyView setRightIv(int resId){
        mIv.setImageResource(resId);
        return this;
    }
    public ModifyView setIvGone(){
        mIv.setVisibility(GONE);
        return this;
    }
    public ModifyView setIvShow(){
        mIv.setVisibility(VISIBLE);
        return this;
    }
    public ModifyView setBackGroundColor(int colorId){
        mRootView.setBackgroundColor(colorId);
        return this;
    }
    public void setModifyEtInputType(int type){
        mModifyEt.setInputType(type);
    }
    public void setModifyEtLength(int length){
        mModifyEt.setFilters(new InputFilter[]{new InputFilter.LengthFilter(length)});
    }
    public void setOnItemClickListener(OnItemClickListener listener,int tag){
        mListener = listener;
        this.tag = tag;
    }
    private OnItemClickListener mListener;

    @Override
    public void onClick(View v) {
        if(mListener!=null){
            mListener.onItemClick(tag);
        }
    }

    public interface OnItemClickListener{
        void onItemClick(int tag);
    }
    public String getModifyEditText(){
       return mModifyEt.getText().toString().trim();
    }


}
